<!--
/**
 *
 * SugarCRM Community Edition is a customer relationship management program developed by
 * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
 *
 * SuiteCRM is an extension to SugarCRM Community Edition developed by SalesAgility Ltd.
 * Copyright (C) 2011 - 2018 SalesAgility Ltd.
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License version 3 as published by the
 * Free Software Foundation with the addition of the following permission added
 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Affero General Public License along with
 * this program; if not, see http://www.gnu.org/licenses or write to the Free
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301 USA.
 *
 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
 *
 * The interactive user interfaces in modified source and object code versions
 * of this program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU Affero General Public License version 3.
 *
 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
 * these Appropriate Legal Notices must retain the display of the "Powered by
 * SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not
 * reasonably feasible for technical reasons, the Appropriate Legal Notices must
 * display the words "Powered by SugarCRM" and "Supercharged by SuiteCRM".
 */

/**
 * Description:
 * Created On: Oct 17, 2005
 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
 * All Rights Reserved.
 * Contributor(s): Chris Nojima
 */
-->

<div id="testSettingsDiv"></div>
<div id="selectFoldersDiv"></div>
<!-- BEGIN: main -->
{MODULE_TITLE}
{ERROR_STRING}
<script type='text/javascript' src='cache/include/javascript/sugar_grp_overlib.js?v={VERSION_MARK}'></script>

<form action="index.php" method="post" name="EditView" id="EditView">
	<input type="hidden" name="module" value="{MODULE}">
	<input type="hidden" name="record" value="{ID}">
	<input type="hidden" name="origin_id" value="{ORIGIN_ID}">
	<input type="hidden" name="isDuplicate" value=false>
	<input type="hidden" name="action">
	<input type="hidden" name="group_id" value="{GROUP_ID}">
	<input type="hidden" name="return_module">
	<input type="hidden" name="return_action">
	<input type="hidden" name="return_id">
	<input type="hidden" name="personal" value="{PERSONAL}">
	<input type="hidden" name="searchField" value="">
	<input type="hidden" id="mailbox_type" name="mailbox_type" value="{MAILBOX_TYPE}">

	<table width="100%" cellpadding="0" cellspacing="0" border="0">
		<tr>
			<td>
				<input title="{APP.LBL_SAVE_BUTTON_TITLE}" accessKey="{APP.LBL_SAVE_BUTTON_KEY}" class="button" onclick="this.form.action.value='Save'; {CHOOSER_SCRIPT} this.form.return_id.value='{RETURN_ID}'; return checkformdata()" type="submit" name="button" id="button" value="  {APP.LBL_SAVE_BUTTON_LABEL}  " {IE_DISABLED}>
				<input title="{APP.LBL_CANCEL_BUTTON_TITLE}" accessKey="{APP.LBL_CANCEL_BUTTON_KEY}" class="button" id="emailCancel" onclick="this.form.action.value='{RETURN_ACTION}'; this.form.module.value='{RETURN_MODULE}'; this.form.record.value='{RETURN_ID}'; if(this.form.record.value == '' && this.form.origin_id.value != '') this.form.record.value=this.form.origin_id.value;" type="submit" name="button" value="  {APP.LBL_CANCEL_BUTTON_LABEL}  ">
				<input title="{MOD.LBL_TEST_BUTTON_TITLE}"
					type='button'
					class="button"
					id="emailTestSettings"
					onClick='ie_test_open_popup_with_submit("InboundEmail", "Popup", "Popup", 400, 300, trim(this.form.server_url.value), this.form.protocol.value, trim(this.form.port.value), trim(this.form.email_user.value), Rot13.write(this.form.email_password.value), trim(this.form.mailbox.value), this.form.ssl.checked, this.form.personal.value, "EditView", this.form.origin_id.value?this.form.origin_id.value:this.form.record.value);'
					name="button" value="  {MOD.LBL_TEST_SETTINGS}  " {IE_DISABLED}>
			</td>
			<td align="right" width="20%" NOWRAP><span class="required">{APP.LBL_REQUIRED_SYMBOL}</span> {APP.NTC_REQUIRED}</td>
			<td align='right'>{ADMIN_EDIT}</td>
		</tr>
	</table>

    <div class="edit view">
	<table width="100%" border=0 cellspacing="{GRIDLINE}" cellpadding="0">
		<tr>
		      <th align="left" scope="row" colspan="1"><h4>{MOD.LBL_BASIC}</h4></th>
		</tr>
		<tr>
		<td>&nbsp;</td>
		<td style="vertical-align:bottom;"><a href="javascript:void(0);" id="prefill_gmail_defaults_link" onclick="javascript:prefillGmailDefaults();">{APP.LBL_EMAIL_ACCOUNTS_GMAIL_DEFAULTS}</a>&nbsp;</td>
		</tr>
		<tr>
			<td valign="top" scope="row" width="15%" NOWRAP>
				<span>{MOD.LBL_NAME}: <span class="required">{APP.LBL_REQUIRED_SYMBOL}</span>&nbsp;</span></td>
			<td valign="top"  width="35%">
				<span><input name='name' id='name' tabindex='10' size='30' maxlength='255' type="text" value="{NAME}" {IE_DISABLED}></span></td>
			<td valign="top" scope="row">
				<span>{MOD.LBL_STATUS}:&nbsp;</span></td>
			<td valign="top"  width="35%"><span>
				<select name='status' tabindex='60' {IE_DISABLED}>{STATUS}</select></span></td>
		</tr>
		<tr>
			<td valign="top" scope="row">
					<span>{MOD.LBL_SERVER_URL}: <span class="required">{APP.LBL_REQUIRED_SYMBOL}</span>&nbsp;</span></td>
			<td valign="top"  width="35%">
				<span><input id='server_url' name='server_url' tabindex='20' size='30' maxlength='100' type="text" value="{SERVER_URL}" {IE_DISABLED}></span></td>
			<td valign="top" scope="row">
				<span>{MOD.LBL_LOGIN}:
				<span class="required">{APP.LBL_REQUIRED_SYMBOL}</span>&nbsp;</span></td>
			<td valign="top"  width="35%">
				<span><input name='email_user' id='email_user' tabindex='70' size='30' maxlength='100' type="text" value="{USER}" autocomplete="off" {IE_DISABLED}></span></td>
		</tr>
		<tr>
			<td valign="top" scope="row" width="15%" NOWRAP>
				<span>{MOD.LBL_SERVER_TYPE}:
				<span class="required">{APP.LBL_REQUIRED_SYMBOL}</span>&nbsp;</span></td>
			<td valign="top"  width="35%">
				<span>
				<select name='protocol' id="protocol" tabindex='30' onchange="toggle_monitored_folder(this); setPortDefault();" {IE_DISABLED}>{PROTOCOL}</select></span></td>
			<td valign="top" scope="row">
				<span>{MOD.LBL_PASSWORD}:
				<span class="required">{EMAIL_PASS_REQ_SYMB}&nbsp;</span></td>
			<td valign="top"  width="35%">
				<span>
				<input name='email_password' id="email_password" tabindex='80' size='30' maxlength='100' type="password" autocomplete="off" {IE_DISABLED}>
				<a href="javascript:void(0)" id='email_password_link' onClick="SUGAR.util.setEmailPasswordEdit('email_password')" style="display: none">{APP.LBL_CHANGE_PASSWORD}</a>
				</span></td>
		</tr>
		<tr>
			<td valign="top" scope="row" width="15%" NOWRAP>
				<span>{MOD.LBL_PORT}:
				<span class="required">{APP.LBL_REQUIRED_SYMBOL}</span>&nbsp;</span></td>
			<td valign="top"  width="35%">
				<span>
				<input name='port' id='port' tabindex="40" value="{PORT}" size='10' {IE_DISABLED}>
			<td valign="top" scope="row" width="15%" NOWRAP>
				<span><span id="label_inbox" >{MOD.LBL_MAILBOX}: <span class="required">{APP.LBL_REQUIRED_SYMBOL}</span></span>&nbsp;</span></td>
			<td valign="top"  width="35%">
				<span><input id="mailbox" name='mailbox' tabindex='90' size='30' maxlength='500' type="text" value="{MAILBOX}">
					<input type="button" id="subscribeFolderButton" style="display:none;" class="button" onclick='javascript:getFoldersListForInboundAccount("InboundEmail", "ShowInboundFoldersList", "Popup", 400, 300, this.form.server_url.value, this.form.protocol.value, this.form.port.value, this.form.email_user.value, Rot13.write(this.form.email_password.value), this.form.mailbox.value, this.form.ssl.checked, this.form.personal.value, this.form.searchField.value, "EditView");' value="{MOD.LBL_SELECT}">
				</span></td>
		</tr>
		<tr>
			<td valign="top" scope="row" width="15%" NOWRAP>
				<span><span>{MOD.LBL_SSL}:&nbsp;{TIPS.LBL_SSL_DESC}</span></span>
			</td>
			<td valign="top"  width="35%">
				<span>
				<input name='ssl' id='ssl' tabindex='45' {CERT} value='1' type='checkbox' {SSL} onClick="setPortDefault();" {IE_DISABLED}>
				</span>
			</td>
			<td id="trashFolderRow" valign="top" scope="row" width="15%" NOWRAP>
				<span>{MOD.LBL_TRASH_FOLDER}:
				<span name="trashRequiredSpan" id="trashRequiredSpan" class="required">{APP.LBL_REQUIRED_SYMBOL}</span>&nbsp;</span></td>
			<td id="trashFolderRow1" valign="top"  width="35%">
				<span>
				<input name='trashFolder' id='trashFolder' tabindex="92" value="{TRASHFOLDER}" size='30' maxlength='100' type="text">
				<input type="button" id="trashFolderButton" class="button" onclick='javascript:getFoldersListForInboundAccount("InboundEmail", "ShowInboundFoldersList", "Popup", 400, 300, this.form.server_url.value, this.form.protocol.value, this.form.port.value, this.form.email_user.value, Rot13.write(this.form.email_password.value), this.form.trashFolder.value, this.form.ssl.checked, this.form.personal.value, "trash", "EditView");' value="{MOD.LBL_SELECT}">
		</tr>
		<tr id="sentFolderRow">
			<td valign="top" scope="row">
				<span>&nbsp;</span></td>
			<td valign="top"  width="35%"><span>
				&nbsp;</span></td>
			<td valign="top" scope="row" width="15%" NOWRAP>
				<span>{MOD.LBL_SENT_FOLDER}:</span></td>
			<td valign="top"  width="35%">
				<span><input id="sentFolder" name='sentFolder' tabindex='95' size='30' maxlength='100' type="text" value="{SENTFOLDER}">
					<input type="button" id="sentFolderButton" class="button" onclick='javascript:getFoldersListForInboundAccount("InboundEmail", "ShowInboundFoldersList", "Popup", 400, 300, this.form.server_url.value, this.form.protocol.value, this.form.port.value, this.form.email_user.value, Rot13.write(this.form.email_password.value), this.form.sentFolder.value, this.form.ssl.checked, this.form.personal.value, "sent", "EditView");' value="{MOD.LBL_SELECT}">
				</span>
			</td>
		</tr>
	</table>
	</div>
    <div class="edit view">
	<table width="100%" border="0" cellspacing="{GRIDLINE}" cellpadding="0">
		<tr>
		<th align="left" scope="row" colspan="4"><h4>{EMAIL_OPTIONS}</h4></th>
		</tr>
		<tr>
			<td valign="top" scope="row" width="15%" NOWRAP>
				<span>
				&nbsp;</span></td>

			<td valign="top"  width="35%">
				<span>
				&nbsp;</span></td>
			<td valign="top" scope="row" width="15%" NOWRAP>
				<span>{MOD.LBL_FROM_NAME}:<span class="required">{APP.LBL_REQUIRED_SYMBOL}</span>&nbsp;</span></td>
			<td valign="top"  width="35%">
				<span><input tabindex="300" name="from_name" id="from_name" value="{FROM_NAME}" {IE_DISABLED}>&nbsp;</span></td>
		</tr>
		<tr>
			<td valign="top" scope="row" width="15%" NOWRAP>
			<span><span style="{AUTO_IMPORT_STYLE}">{MOD.LBL_ENABLE_AUTO_IMPORT}:&nbsp;{TIPS.LBL_ASSIGN_TO_GROUP_FOLDER_DESC}</span></span>&nbsp;
			</td>
			<td valign="top"  width="15%" NOWRAP>
			 <input name='is_auto_import' style="{AUTO_IMPORT_STYLE}" id='is_auto_import' onclick="showWarningsIfChaningAutoImport();"tabindex='45' type='checkbox' {IS_AUTO_IMPORT}>
			</td>
			<td valign="top" scope="row" width="15%" NOWRAP>
				<span>{MOD.LBL_FROM_ADDR}:<span class="required">{APP.LBL_REQUIRED_SYMBOL}</span>{TIPS.LBL_FROM_ADDR_DESC}</span></td>
			<td valign="top"  width="35%">
				<span><input tabindex="310" name="from_addr" id="from_addr" value="{FROM_ADDR}" {IE_DISABLED}></span></td>
		</tr>
		<tr>
			<td valign="top" scope="row">
				<slot style="{MAILBOX_TYPE_STYLE}">{MOD.LBL_CREATE_CASE}:&nbsp;{TIPS.LBL_CREATE_CASE_HELP}</span></td>
			<td valign="top"  width="35%"><slot style="{MAILBOX_TYPE_STYLE}">
			     <input name='is_create_case' id='is_create_case' onclick="showCreateCaseRow();"tabindex='45' type='checkbox' {IS_CREATE_CASE} {IE_DISABLED}></span></td>
			<td valign="top" scope="row" width="15%" NOWRAP>
				{MOD.LBL_REPLY_TO_NAME}:&nbsp;
			</td>
			<td valign="top"  width="35%">
				<input tabindex="320" name="reply_to_name" value="{REPLY_TO_NAME}" {IE_DISABLED}>
			</td>
		</tr>
		<tr id="createCaseRow" style="{CREATE_CASE_ROW_STYLE}">
			<td valign="top" scope="row">
				<span>{MOD.LBL_DISTRIBUTION_METHOD}:&nbsp;</span></td>
			<td valign="top"  width="35%"><span>
				<select id='distrib_method' name='distrib_method' tabindex='241'>{DISTRIBUTION_METHOD}</select>&nbsp;&nbsp;

                <span id="distribution_user">
                <input type="text" name="distribution_user_name" class="sqsEnabled" tabindex="0" id="distribution_user_name" size="" value="{distribution_user_name}" title='' autocomplete="off"  	 >
                <input type="hidden" name="distribution_user_id" id="distribution_user_id" value="{distribution_user_id}">
<span class="id-ff multiple">
<button type="button" name="btn_distribution_user_name" id="btn_distribution_user_name" tabindex="0" title="Select User" class="button firstChild" value="Select User"
        onclick='open_popup(
                "Users",
                600,
                400,
                "",
                true,
                false,
        {"call_back_function":"set_return","form_name":"EditView","field_to_name_array":{"id":"distribution_user_id","last_name":"distribution_user_name"}},
                "single",
                true
                );' >
    <span class="suitepicon suitepicon-action-select"></span></button><button type="button" name="btn_clr_distribution_user_name" id="btn_clr_distribution_user_name" tabindex="0" title="Clear User"  class="button lastChild"
                                                                       onclick="SUGAR.clearRelateField(this.form, 'distribution_user_name', 'distribution_user_id');"  value="Clear User" ><span class="suitepicon suitepicon-action-clear"></span></button>
</span>
                <script type="text/javascript">
                    if(typeof sqs_objects == 'undefined'){
                        var sqs_objects = new Array;
                    }
                    sqs_objects['EditView_distribution_user_name']={
                        "form":"EditView",
                        "method":"get_user_array",
                        "field_list":["user_name","id"],
                        "populate_list":["distribution_user_name","distribution_user_id"],
                        "required_list":["distribution_user_id"],
                        "conditions":[{"name":"user_name","op":"like_custom","end":"%","value":""}],
                        "limit":"30",
                        "no_match_text":"No Match"};
                    SUGAR.util.doWhen(
                            "typeof(sqs_objects) != 'undefined' && typeof(sqs_objects['EditView_distribution_user_name']) != 'undefined'",
                            enableQS
                    );
                </script>
                </span>
                &nbsp;&nbsp;

                {DISTRIBUTION_OPTIONS}</span></td>
			<td valign="top" scope="row">
				<span>&nbsp;</span></td>
			<td valign="top"  width="35%"><span>
				&nbsp;</span></td>
		</tr>
		<tr id="createCaseRow1" style="{CREATE_CASE_ROW_STYLE}">
			<td valign="top" scope="row" width="15%" NOWRAP >
				<span>{MOD.LBL_CREATE_CASE_REPLY_TEMPLATE}:&nbsp;{TIPS.LBL_CREATE_CASE_REPLY_TEMPLATE_HELP}</span></td>
			<td colspan="3" valign="top"  width="35%">
				<span>
					<select tabindex='330' id="create_case_template_id" name='create_case_template_id' onchange="show_edit_template_link(this, 'create_case_edit_template');" {IE_DISABLED}>{CREATE_CASE_EMAIL_TEMPLATE_OPTIONS}</select>
					<input type="button" class="button" onclick="javascript:open_email_template_form('create_case_template_id')" value="{MOD.LBL_CREATE_TEMPLATE}" {IE_DISABLED}>
					<input type="button" class="button" name='create_case_edit_template' id='create_case_edit_template' style="{CREATE_CASE_EDIT_TEMPLATE}" onclick="javascript:edit_email_template_form('create_case_template_id')" value="{MOD.LBL_EDIT_TEMPLATE}">
				</span>
			</td>
		</tr>
		<tr>
			<td valign="top" scope="row">
				<span>&nbsp;</span></td>
			<td valign="top"  width="35%"><span>
				&nbsp;</span></td>
			<td valign="top" scope="row" width="15%" NOWRAP>
				{MOD.LBL_REPLY_TO_ADDR}:&nbsp;
			</td>
			<td valign="top"  width="35%">
				<input tabindex="340" name="reply_to_addr" value="{REPLY_TO_ADDR}" {IE_DISABLED}>&nbsp;
			</td>
		</tr>
		<tr style="MAILBOX_TYPE_STYLE">
			<td valign="top" scope="row">
				<span>&nbsp;</span></td>
			<td valign="top"  width="35%"><span>
				&nbsp;</span></td>
			<td valign="top" scope="row" width="15%" >
			 <slot style="{MAILBOX_TYPE_STYLE}">{MOD.LBL_ALLOW_OUTBOUND_GROUP_USAGE}:&nbsp;{TIPS.LBL_ALLOW_OUTBOUND_GROUP_USAGE_DESC}</span>
		  </td>
			<td valign="top"  width="35%">
			 <slot style="{MAILBOX_TYPE_STYLE}"><input name='allow_outbound_group_usage' id='allow_outbound_group_usage' tabindex='45' value='1' type='checkbox' {ALLOW_OUTBOUND_USAGE} ></span>
			</td>
		</tr>
		<tr>
			<td valign="top" scope="row" width="15%" NOWRAP>
				<slot style="{CREATE_GROUP_FOLDER_STYLE}">{MOD.LBL_AUTOREPLY}:&nbsp;{TIPS.LBL_AUTOREPLY_HELP}</span></td>
			<td colspan="3" valign="top"  width="35%">
				<slot style="{CREATE_GROUP_FOLDER_STYLE}">
					<select tabindex='251' id="template_id" name='template_id' onchange="show_edit_template_link(this, 'edit_template');" {IE_DISABLED}>{EMAIL_TEMPLATE_OPTIONS}</select>
					<input type="button" class="button" onclick="javascript:open_email_template_form('template_id')" value="{MOD.LBL_CREATE_TEMPLATE}" {IE_DISABLED}>
					<input type="button" value="{MOD.LBL_EDIT_TEMPLATE}" class="button" onclick="javascript:edit_email_template_form('template_id')" name='edit_template' id='edit_template' style="{EDIT_TEMPLATE}">
				</span>
			</td>
		</tr>
		<tr>
			<td valign="top" scope="row" width="18%" NOWRAP>
				<slot style="{CREATE_GROUP_FOLDER_STYLE}">{MOD.LBL_FILTER_DOMAIN}:&nbsp;{TIPS.LBL_FILTER_DOMAIN_DESC}</span></td>
			<td valign="top"  width="35%">
				<slot style="{CREATE_GROUP_FOLDER_STYLE}"><input tabindex="270" name="filter_domain" value="{FILTER_DOMAIN}" {IE_DISABLED}></span></td>
			<td valign="top" scope="row">
				<span><span style="{CREATE_GROUP_FOLDER_STYLE}">{MOD.LBL_MAX_AUTO_REPLIES}:&nbsp;{TIPS.LBL_MAX_AUTO_REPLIES_DESC}</span></span></td>
			<td valign="top"  width="35%">
				<span><input tabindex="271" style="{CREATE_GROUP_FOLDER_STYLE}" name="email_num_autoreplies_24_hours" value="{EMAIL_NUM_AUTOREPLIES_24_HOURS}"></span></td>
		</tr>
		<tr id = "leaveMessagesOnMailServerRow" style="{LEAVEMESSAGESONMAILSERVER_STYLE}">
			<td valign="top" scope="row" width='20%'>
				<span>{MOD.LBL_MARK_READ}:</span></td>
			<td valign="top"  width='30%'>
				<select name='leaveMessagesOnMailServer' tabindex='253'>{LEAVEMESSAGESONMAILSERVER}</select></td>
			<td valign="top" scope="row">
				<span>&nbsp;</span></td>
			<td valign="top"  width="35%"><span>
				&nbsp;</span></td>
		</tr>
	</table>
	</div>


</form>

<script type="text/javascript" lang="Javascript" src="modules/InboundEmail/InboundEmail.js?v={VERSION_MARK}"></script>
<script type="text/javascript">

var fieldToSetValue = '';
function checkformdata() {
	return (check_form('EditView') && checkOtherFields() && checkTrashFolder() );
}

function prefillGmailDefaults(){

        document.getElementById('server_url').value = "imap.gmail.com";
        document.getElementById('ssl').checked = true;
        document.getElementById('protocol').value = "imap";

        toggle_monitored_folder(document.getElementById('protocol'));
        setPortDefault();
}
function checkOtherFields() {
	var from_name = document.getElementById('from_name').value;
	var from_addr = document.getElementById('from_addr').value;
	if (trim(from_name) == '' || trim(from_addr) == '') {
	    requiredTxt = SUGAR.language.get('app_strings', 'ERR_MISSING_REQUIRED_FIELDS');
	    invalidTxt = SUGAR.language.get('app_strings', 'ERR_INVALID_VALUE');
	    if (trim(from_name) == '') {
	    	add_error_style('EditView',  'from_name', requiredTxt + 	" From Name");
	    } // if
	    if (trim(from_addr) == '') {
	    	add_error_style('EditView',  'from_addr', requiredTxt + 	" From Address");
	    } // if
		return false;
	} else {
		return true;
	} // else
} // fn


function checkTrashFolder() 
{
	if (document.getElementById('protocol').value == 'imap' && document.getElementById('mailbox_type').value != 'bounce') {
		var trashFolderValue = document.getElementById("trashFolder").value;
		if (trim(trashFolderValue).length <= 0) {
		    requiredTxt = SUGAR.language.get('app_strings', 'ERR_MISSING_REQUIRED_FIELDS');
		    invalidTxt = SUGAR.language.get('app_strings', 'ERR_INVALID_VALUE');
		    add_error_style('EditView',  'trashFolder', requiredTxt + 	" Trash Folder");
			return false;
		} else {
			return true;
		}
	} else {
		return true;
	} // else
} // fn

function showCreateCaseRow() {
	var createCaseRow = document.getElementById('createCaseRow');
	var createCaseRow1 = document.getElementById('createCaseRow1');
	var isCreateCase = document.getElementById('is_create_case').checked;
	var autoImportEl = document.getElementById('is_auto_import');

	if (isCreateCase) {
		createCaseRow.style.display = '';
		createCaseRow1.style.display = '';
		autoImportEl.checked = true;
	} else {
		createCaseRow.style.display = 'none';
		createCaseRow1.style.display = 'none';
		possibleActionChange();
	} // else
} // fn

function possibleActionChange() {
	var mailBoxType = document.getElementById('mailbox_type');
	var trashRequiredSpan = document.getElementById('trashRequiredSpan');
	if(mailBoxType.value == 'bounce') {

		trashRequiredSpan.style.display = 'none';
		trashRequiredSpan.style.display = 'none';
	} else {
		trashRequiredSpan.style.display = '';
		trashRequiredSpan.style.display = '';
	} // else
}

function show_edit_template_link(field, editTemplate) {
	var field1=document.getElementById(editTemplate);
	if (field.selectedIndex == 0) {
		field1.style.visibility="hidden";
	}
	else {
		field1.style.visibility="visible";
	}
}

function refresh_email_template_list(template_id, template_name) {
	var field=document.getElementById(fieldToSetValue);
	var bfound=0;
	for (var i=0; i < field.options.length; i++) {
			if (field.options[i].value == template_id) {
				if (field.options[i].selected==false) {
					field.options[i].selected=true;
				}
				field.options[i].text = template_name;
				bfound=1;
			}
	}
	//add item to selection list.
	if (bfound == 0) {
		var newElement=document.createElement('option');
		newElement.text=template_name;
		newElement.value=template_id;
		field.options.add(newElement);
		newElement.selected=true;
	}

	//enable the edit button.
	var editButtonName = 'edit_template';
	if (fieldToSetValue == 'create_case_template_id') {
		editButtonName = 'create_case_edit_template';
	} // if
	var field1=document.getElementById(editButtonName);
	field1.style.visibility="visible";

	var applyListToTemplateField = 'template_id';
	if (fieldToSetValue == 'template_id') {
		applyListToTemplateField = 'create_case_template_id';
	} // if
	var field=document.getElementById(applyListToTemplateField);
	if (bfound == 1) {
		for (var i=0; i < field.options.length; i++) {
			if (field.options[i].value == template_id) {
				field.options[i].text = template_name;
			} // if
		} // for

	} else {
		var newElement=document.createElement('option');
		newElement.text=template_name;
		newElement.value=template_id;
		field.options.add(newElement);
	} // else
}


function open_email_template_form(fieldToSet) {
	fieldToSetValue = fieldToSet;
	URL="index.php?module=EmailTemplates&action=EditView&inboundEmail=true&show_js=1";
	windowName = 'email_template';
	windowFeatures = 'width=800' + ',height=600' 	+ ',resizable=1,scrollbars=1';

	win = window.open(URL, windowName, windowFeatures);
	if(window.focus)
	{
		// put the focus on the popup if the browser supports the focus() method
		win.focus();
	}
}
function edit_email_template_form(templateField) {
	fieldToSetValue = templateField;
	var field=document.getElementById(templateField);
	URL="index.php?module=EmailTemplates&action=EditView&inboundEmail=true&show_js=1";
	if (field.options[field.selectedIndex].value != 'undefined') {
		URL+="&record="+field.options[field.selectedIndex].value;
	}
	windowName = 'email_template';
	windowFeatures = 'width=800' + ',height=600' 	+ ',resizable=1,scrollbars=1';

	win = window.open(URL, windowName, windowFeatures);
	if(window.focus)
	{
		// put the focus on the popup if the browser supports the focus() method
		win.focus();
	}
}
function open_group_folder_form() {
	URL="index.php?module=InboundEmail&action=EditGroupFolder&target=Popup&to_pdf=1";
	windowName = 'group_folder_popup_window';
	windowFeatures = 'width=400' + ',height=300' 	+ ',resizable=1,scrollbars=1';

	win = window.open(URL, windowName, windowFeatures);
	if(window.focus)
	{
		// put the focus on the popup if the browser supports the focus() method
		win.focus();
	}

}
function edit_group_folder_form() {
	URL="index.php?module=InboundEmail&action=EditGroupFolder&target=Popup&to_pdf=1";
	var field=document.getElementById('group_folder_id');
	if (field.options[field.selectedIndex].value != 'undefined') {
		URL+="&record="+field.options[field.selectedIndex].value;
	}
	windowName = 'edit_group_folder_popup_window';
	windowFeatures = 'width=400' + ',height=300' 	+ ',resizable=1,scrollbars=1';

	win = window.open(URL, windowName, windowFeatures);
	if(window.focus)
	{
		// put the focus on the popup if the browser supports the focus() method
		win.focus();
	}

}
function refresh_group_folder_list(groupFolder_id, groupFolder_name) {
	var field=document.getElementById('group_folder_id');
	var bfound=0;
	for (var i=0; i < field.options.length; i++) {
			if (field.options[i].value == groupFolder_id) {
				if (field.options[i].selected==false) {
					field.options[i].selected=true;
				}
				field.options[i].text = groupFolder_name;
				bfound=1;
			}
	}
	//add item to selection list.
	if (bfound == 0) {
		var newElement=document.createElement('option');
		newElement.text=groupFolder_name;
		newElement.value=groupFolder_id;
		field.options.add(newElement);
		newElement.selected=true;
	}
	//enable the edit button.
	var field1=document.getElementById('edit_group');
	field1.style.visibility="visible";
	showCreateCaseRow();
	showHideLeaveMessagesOnMailServer();
}

function show_edit_group_folder_link(field) {

	var field1=document.getElementById('edit_group');
	if (field.selectedIndex == 0) {
	}
	else {
		field1.style.visibility="visible";
	}
	showCreateCaseRow();
	showHideLeaveMessagesOnMailServer();
}

function showHideLeaveMessagesOnMailServer() {
	var field=document.getElementById('group_folder_id');
	var leaveMessagesOnMailServerRow = document.getElementById('leaveMessagesOnMailServerRow');
	if (field.selectedIndex == 0) {
		leaveMessagesOnMailServerRow.style.display="none";
	}
	else {
		leaveMessagesOnMailServerRow.style.display='';
	}

} // fn

function showWarningsIfChaningAutoImport() {

    var isAutoImportOn = document.getElementById('is_auto_import').checked;
    var isCreateCase = document.getElementById('is_create_case').checked
    var record = document.forms['EditView'].record.value;
    //Alert if changing for an existing record only.
    if(record != '')
        alert(warningForAutoChange);
    //If the user has create case enabled then auto import must be on.
    if( !isAutoImportOn && isCreateCase)
    {
        document.getElementById('is_auto_import').checked = true;
        alert(warningForAutoChangeWithCreateCase);
    }
}
toggle_monitored_folder(document.getElementById('protocol'));
setPortDefault();
possibleActionChange();

var warningForAutoChange = '{MOD.LBL_WARNING_CHANGING_AUTO_IMPORT}';
var warningForAutoChangeWithCreateCase = '{MOD.LBL_WARNING_CHANGING_AUTO_IMPORT_WITH_CREATE_CASE}';
if(window.addEventListener){
    window.addEventListener("load", function() { SUGAR.util.setEmailPasswordDisplay('email_password', {HAS_PASSWORD},'EditView'); }, false);
}else{
    window.attachEvent("onload", function() { SUGAR.util.setEmailPasswordDisplay('email_password', {HAS_PASSWORD},'EditView'); });
}
</script>
{JAVASCRIPT}
<!-- END: main -->